/**
 * 检查坐骑等级经验数据脚本
 */

const mysql = require('mysql2/promise');

// 数据库配置
const dbConfig = {
  host: '43.143.253.188',
  user: 'nextjs',
  password: 'yEAiRE2jcxTyRBy5',
  database: 'nextjs',
  charset: 'utf8mb4'
};

async function checkMountLevelData () {
  let connection;

  try {
    console.log('🔌 连接数据库...');
    connection = await mysql.createConnection(dbConfig);
    console.log('✅ 数据库连接成功');

    // 检查等级1-40的训练经验数据
    console.log('🔍 检查等级1-40的训练经验数据...');
    const [rows] = await connection.execute(
      'SELECT level, exp_per_training FROM mount_level_experience WHERE level <= 40 ORDER BY level'
    );

    console.log('📊 等级训练经验数据:');
    console.log('等级\t训练经验');
    console.log('----\t--------');
    rows.forEach((row) => {
      console.log(`${row.level}\t${row.exp_per_training}`);
    });

    // 检查特定等级的数据
    console.log('\n🔍 检查特定等级数据...');
    const [level32] = await connection.execute(
      'SELECT * FROM mount_level_experience WHERE level = 32'
    );

    if (level32.length > 0) {
      console.log('📊 等级32数据:', level32[0]);
    } else {
      console.log('❌ 未找到等级32的数据');
    }

    // 检查等级11的数据
    const [level11] = await connection.execute(
      'SELECT * FROM mount_level_experience WHERE level = 11'
    );

    if (level11.length > 0) {
      console.log('📊 等级11数据:', level11[0]);
    } else {
      console.log('❌ 未找到等级11的数据');
    }

  } catch (error) {
    console.error('❌ 检查数据失败:', error.message);
    throw error;
  } finally {
    if (connection) {
      await connection.end();
      console.log('🔌 数据库连接已关闭');
    }
  }
}

// 运行脚本
if (require.main === module) {
  checkMountLevelData().catch((error) => {
    console.error('💥 脚本执行失败:', error.message);
    process.exit(1);
  });
}

module.exports = { checkMountLevelData };
